import java.io.DataOutputStream;
import java.io.IOException;

import java.util.Arrays;
import org.json.JSONObject;

/*
 * Слово, состоящее только из пробелов.
 */
final public class Space extends WordInterface {
    final byte count;

    public Space(final int count) {
        this.count = (byte)count;
    }

    public String toString() {
        return new String(getValue());
    }

    public int length() {
        return count;
    }

    public int compareTo(final WordInterface b) {
        if (b instanceof Space) {
            byte y = ((Space) b).count;
            return (count < y) ? -1 : ((count == y) ? 0 : 1);
        }
        return -1;
    }

    public boolean equals(Space s) {
        return count == s.count;
    }

    char[] getValue() {
        char[] r = new char[count];
        Arrays.fill(r, ' ');
        return r;
    }
    
    JSONObject toJSON() {
        JSONObject jo = new JSONObject();
        jo.put("S", Integer.valueOf(count));
        return jo;
    }

    void write(DataOutputStream dos) throws IOException {
        dos.writeByte(0x53);        // S
        dos.writeByte(count);
    }
}
